package com.drdj.exam;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class CallAndDialer extends Activity {

	private EditText mEtPhoneNum;
	private Button mBtnCall;
	private Button mBtnOpenDialer;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.call_and_dialer);

		mEtPhoneNum = (EditText) findViewById(R.id.etPhoneNum);
		mBtnCall = (Button) findViewById(R.id.btnCall);
		mBtnOpenDialer = (Button) findViewById(R.id.btnOpenDialer);

		/*
		 * make a phone call with the number user typed.
		 * don't forget : add CALL_PHONE permission to AndroidMenifest.xml
		 * <uses-permission android:name="android.permission.CALL_PHONE" />
		 * 
		 */
		mBtnCall.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				String phoneNum = mEtPhoneNum.getText().toString();
				startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNum)));
			}
		});
		
		/*
		 * open dialer with the number user typed.
		 */
		mBtnOpenDialer.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				String phoneNum = mEtPhoneNum.getText().toString();
				startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNum)));
			}
		});

	}
}
